import React, { Component } from 'react';
import { LocaleProvider, Icon } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import PendingLoanQuery from '../../../components/PendingLoanQuery';
import PendingLoanTable from '../../../components/PendingLoanTable';
import TitleBtn from '../../../components/TitleBtn';
import { orderService } from '../../../service/order';

class ForLending extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: []
    };
  }

  newData = [];

  async getData () {
    const res = await orderService.order_list()
    // this.data = res.data.rows;
    res.data.rows.forEach((item) => {
      if(item.state === 0) {
        this.newData.push({
          key: item.id,
          name: item.name,
          phone: item.tel,
          loanCount: item.nums,
          loanState: ['待放款'],
          loanMoney: item.money,
          serveMoney: item.smoney,
          loanInterest: item.amoney,
          loanDate: item.ctime,
          repaymentDate: item.outtime ? item.outtime : '-',
          partRepay:'-',
          ActualRepaymentDate: item.rtime ? item.rtime : '-',
          RepaymentCount: item.rmoney,
          OverdueDays:'-',
          CollectionStatus: item.pstate === 0 ? ['未催收'] : [''],
          Collectter: item.puid ? item.puid : '-',
          CollectionRepayment: item.pmoney,
          auditor:'于宇',
          MOcommissioner:'-',
          cz:['销账', '补扣']
        })
      } 
    })
    this.setState({
      data: this.newData
    });
  }

  initData = () => {
    this.newData = [];
  }

  componentDidMount() {
    this.getData()
  }

  componentWillUnmount() {
    this.initData()
  }

  render() {
    return (
      <LocaleProvider locale={zh_CN}>
        <div className='apply'>
          <div>
						<Icon type="appstore" />
						<span className="apply-font">待放款订单</span>
						<TitleBtn />
          </div>
          <PendingLoanQuery /> 
          <PendingLoanTable data={this.state.data} />
        </div> 
      </LocaleProvider>
    );
  }
}

export default ForLending;